module.exports = (function(){
    var loggers = require('../lib/loggers');
    var util = require('util');

    function control(req, res, next) {
        res.header("Access-Control-Allow-Origin", "*");
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
        next();
    };

    function watcher(req, res, next) {
        var accessLogger = loggers.access;

        var message = util.format('%s %s %s', req.ip, req.protocol, req.path);
        accessLogger.info(message);

        next();
    };

    return {
        control: control,
        watcher: watcher
    };
}());
